const { $util } = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData(options);
    this.getdetail();
  },
  getdetail() {
    $util.request({
      url: 'entry/wxapp/documents.newGetfiledetail',
      data: {
        id: this.data.id,
      },
      showLoading: false,
      success: (res) => {
        const list = res.data;
        wx.setNavigationBarTitle({
          title: res.data.dname,
        });
        this.setData(list);
      },
    });
  },
  opendocument(e) {
    this.setData({
      isdisabled: true,
    });
    wx.showLoading({
      title: '加载中',
    });
    wx.downloadFile({
      url: e.currentTarget.dataset.link,
      success: (res) => {
        const filePath = res.tempFilePath;
        wx.openDocument({
          filePath,
          success: () => {
            this.setData({
              isdisabled: false,
            });
            wx.hideLoading();
            console.log('打开文档成功');
          },
          fail: (error) => {
            this.setData({
              isdisabled: false,
            });
            wx.hideLoading();
            wx.showToast({
              title: error.errMsg,
              icon: 'none',
            });
            console.log(error);
          },
        });
      },
    });
  },
  previewimg(e) {
    wx.previewImage({
      urls: [e.currentTarget.dataset.link],
    });
  },
  onShareAppMessage() {
    return {
      path: '/ws_party_const/pages/document/detail?id=' + this.data.id,
    };
  },
});
